package com.app.TCES.controller;
/*
*管理员 院系设置 控制器
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.app.TCES.domain.Department;

import com.app.TCES.service.A_DeptService;
@Resource
@Controller
public class A_DeptController {
	Logger logger = LogManager.getLogger(A_DeptController.class);
	@Autowired
	A_DeptService a_DeptService;
	
	@ResponseBody
	@RequestMapping("/selectDept")
	public Map<String , Object> toSelectDept(@RequestParam("page")Integer page,@RequestParam("limit")int limit){
		int	tmp=(page-1)*limit;
		logger.debug("page:"+page);
		
		logger.debug("查询学院信息");
		List<Department> list =new ArrayList<Department>();
		Map<String, Object> map = new HashMap<String, Object>();
		list = a_DeptService.selectDept(tmp,limit);
		int tol=a_DeptService.selectDepts();
		logger.debug("总数tol:"+tol);
		logger.debug("返回学院信息");
		map.put("tol", tol);
		map.put("message", "学院信息查询成功");
		map.put("status", 200);
		map.put("list", list);
		
		return map;
	}

/*	@RequestMapping("/deletDept")
	public Map<String, String> deleterace(int deptId){
		logger.debug("===========删除"+deptId);
		a_DeptService.delDept(deptId);
		Map<String, String> map = new HashMap<>();
		map.put("msg", "删除成功");
		return map;
	}*/
	
	@ResponseBody
	@RequestMapping("/updateDept")
	public Map<String , String> updateDept(String deptName,int deptId){
		a_DeptService.updateDept(deptName, deptId);
		logger.debug("deptName______"+deptName);
		logger.debug("deptId_____"+deptId);
		Map<String , String > map = new HashMap<>();
		map.put("msg", "YES");
		return map;
		
	}
	@ResponseBody
	@RequestMapping("/insertDept")
	public Map<String, String> insertDept(int deptId,String deptName){
		a_DeptService.insertDept(deptId, deptName);
		logger.debug("deptName______"+deptName);
		logger.debug("deptId_____"+deptId);
		Map<String, String> map = new HashMap<>();
		map.put("msg", "YES");
		return map;
	}
	
}
